import React, { Component } from 'react'
import './index.css';
import axios from 'axios';
export default class YiYan extends Component {
    state = {
        msg: ''
    }
    render() {
        return (
            <div className="container-yiyan">
                <div className="mask"></div>

                <div className="content">
                    <div className="top">『</div>
                    <div className="text">{this.state.msg}</div>
                    <div className="bottom">』</div>
                </div>
            </div>
        )
    }

    componentDidMount(){
        this.load();

        setInterval(() => {
            this.load();
        }, 5000);
    }

    load = async () => {
        //发送 ajax 请求获取一言
        let result =await axios('http://poetry.apiopen.top/sentences');
        //提取
        let msg = result.data.result.name
        //设置 msg
        this.setState({
            msg: msg
        })
    }
}
